var _webRoot_Path = "/HyManageSystem";
var modules = [ {
	include : true,
	incfile : _webRoot_Path+'/style/common/reset.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/button_a.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/list.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_dept_worker.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_cw_subject_funds.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/frameworkutil.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/ymPrompt.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/skin/vista/ymPrompt.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.scrollabletable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.jscrollable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/jquery.tablesorter.js'
} ];

for ( var i = 0; i < modules.length; i++) {
	if (modules[i].include === true) {
		filename = modules[i].incfile;
		if (jQuery.browser.safari) {
			jQuery.ajax({
				url : filename,
				dataType : 'script',
				async : false,
				cache : true
			});
		} else {
			var fileType = filename.substring(filename.lastIndexOf('.') + 1,
					filename.length).toUpperCase();
			if (fileType == 'JS') {
				IncludeJavaScript(filename);
			} else if (fileType == 'CSS') {
				IncludeCss(filename);
			}
		}
	}
}
function changeForSelect(p_dotype,p_doType,doid){
	var str = "";
	if(p_dotype==1){
		str="[{id:'"+doid+"'}]";
	}else{
		var checkedBox = $(":checkbox[name='dot_dc_data'][checked]");
		if(checkedBox.length<= 0){
			alert('请选择要修改的记录');return;
		}
		str="[";
		var i=0;
		checkedBox.each(function() {
			str+="{";
			str+="id:'"+$(this).attr("id")+"'";
			str+="}";
			if(i< checkedBox.length-1){
				str+=",";
			}
			i++;
		});
		str+="]";
	}
	var datas = {
			'p_doType':p_doType,
			'p_doFlid':"state",
	        'p_selectList': str
	    };
    if(confirm("您确定执行该记录修改操作吗？")){
    	var url = _rootPath+'/v/weibo/changeForSelect';
    	postData(url, datas, function(msg){
    		if(msg.infoNo==1){
				alert(msg.infoStr);
				window.location.reload(true);
			}else if(msg.infoNo==-9999){
				alert(msg.infoStr);
				return;
			}else if(msg.infoNo==-1000){
				window.location.href=_webRoot_Path+"/v/system/error";
				return;
			}else{
				alert(msg.infoStr);
			}
        });
	}
}
/**
 * 导入JS文件到页面
 * 
 * @param jsFile
 */
function IncludeJavaScript(jsFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.charset = 'utf-8';
	oScript.src = jsFile;
	oHead.appendChild(oScript);
};

/**
 * 导入CSS文件到页面
 * 
 * @param cssFile
 */
function IncludeCss(cssFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oLink = document.createElement('link');
	oLink.rel = "stylesheet";
	oLink.type = 'text/css';
	oLink.href = cssFile;
	oHead.appendChild(oLink);
};


function searchData(){
    var p_state = $("#p_state").val();
    location.href = _rootPath + "/v/weibo/index?p_state=" + p_state;
  
};
function ReadFiles(){
    var fileName = $("#ff1").val();
    var fileType = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length).toUpperCase();
    switch (fileType) {
        case 'XLS':
            sycnXLS(fileName);
            break;
        case 'XLSX':
            sycnXLS(fileName);
            break;
        default:
        	alert('请上传正确的格式，如:xls')
        	break;
    }
}

function sycnXLS(files){
    var fso;
    try {
        fso = new ActiveXObject("Excel.application"); //得到Excel应用程序的对象
    } 
    catch (e) {
        alert('要导入该表，您必须安装Excel电子表格软件，同时IE设置如下：\n打开IE浏览器的工具-〉Internet选项-〉安全-〉自定义级别中的‘对没有标记为安全的ActiveX控件进行初始化和脚本运行’设置为‘启用’即可！');
        return;
    }
    var ts = fso.Workbooks.open(files); //得到Excel工作薄对象
    ts.worksheets(1).select(); //选择第一个工作表
    var oSheet = ts.ActiveSheet; //得到第一个工作表对象
    var rows = oSheet.UsedRange.Rows.Count; //得到有效数据行个数
    var i = 0;
    var str = "[";
    for (var i = 1; i <= rows; i++) {
        str += "{";
        str += "uid:'" + oSheet.cells(i, 1).value + "',";
        str += "sex:'" + oSheet.cells(i, 2).value + "',";
        str += "userName:'" + oSheet.cells(i, 3).value + "',";
        str += "friendCount:'" + oSheet.cells(i, 4).value + "',";
        str += "attentionCount:'" + oSheet.cells(i, 5).value + "',";
        str += "weiboCount:'" + oSheet.cells(i, 6).value + "',";
        str += "collectCount:'" + oSheet.cells(i, 7).value + "',";
        str += "mutualPowderCount:'" + oSheet.cells(i, 8).value + "',";
        str += "address:'" + oSheet.cells(i, 9).value + "',";
        str += "language:'" + oSheet.cells(i, 10).value + "',";
        str += "authentication:'" + oSheet.cells(i, 11).value + "',";
        str += "regiDate:'" + oSheet.cells(i, 12).value + "',";
        str += "accountQuality:'" + oSheet.cells(i, 14).value + "',";
        str += "accountAttribute:'" + oSheet.cells(i, 15).value + "',";
        str += "indexNumber:'" + oSheet.cells(i, 16).value + "',";
        str += "inviteSituation:'" + oSheet.cells(i, 17).value + "',";
        str += "feedback:'" + oSheet.cells(i, 18).value + "'";
        str += "}";
        if (i != rows) {
            str += ",";
        }
    }
    str += "]";
    var dates = {
        'ds': str
    };
    var url = _rootPath + "/v/weibo/addWeiboUser";
    var b = "你是否确定进行该操作?";
    if (confirm(b)) {
        postData(url, dates, function(msg){
            if (msg.infoNo == 1) {
                alert("导入成功");
                window.location.reload();
            }
            else {
                alert(msg.infoStr);
            }
        });
    }
    ts.Close();
    fso.Quit();
}
